package com.itg.vms.servlet;

import com.itg.vms.entity.Movies;
import com.itg.vms.service.MoviesService;
import com.itg.vms.service.impl.MoviesServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zjzaki
 * @create 2023年03月08日 00:10:00
 */
@WebServlet("/movies")
public class IndexServlet extends BaseServlet {

    /**
     * 业务层
     */
    MoviesService moviesService = new MoviesServiceImpl();

    /**
     * 查询电影信息
     */
    public void getMovies(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //调用servlet
        new MoviesServlet().selectAllMovies(req, resp);
    }

    /**
     * 通过id查询电影详细信息
     *
     * @author zjzaki
     */
    public void getMovieDetailById(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //得到请求的参数
        String id = req.getParameter("id");
        int mid = Integer.parseInt(id);
        Movies movieDetail = moviesService.getMovieDetailById(mid);

        if (movieDetail != null) {
            resp.getWriter().write(success(movieDetail));
        }else{
            resp.getWriter().write(error("查询失败"));
        }
    }
}
